package com.yanqu.road.server.logic.recharge;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.douluodalu.config.DouLuoDaLuConfig;
import com.yanqu.road.entity.activity.douluodalu.config.DouLuoDaLuEventInfo;
import com.yanqu.road.entity.activity.douluodalu.enums.eDouLuoDaLuEventType;
import com.yanqu.road.entity.config.goods.MallInfo;
import com.yanqu.road.entity.enums.eLogMoneyType;
import com.yanqu.road.entity.log.LogDouLuoDaLuBuyRmbMall;
import com.yanqu.road.entity.recharge.RechargeOrder;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.douluodalu.DouLuoDaLuModule;
import com.yanqu.road.server.gameplayer.module.player.CurrencyModule;
import com.yanqu.road.server.manger.activity.douluodalu.DouLuoDaLuMgr;
import com.yanqu.road.server.manger.log.AutoLogMgr;
import com.yanqu.road.server.manger.log.LogMgr;
import com.yanqu.road.utils.property.PropertyHelper;

import java.util.List;

/**
 * 斗罗大陆
 */
public class DouLuoDaLuActivityRecharge extends BaseRecharge {

    public DouLuoDaLuActivityRecharge(GamePlayer player, MallInfo mallInfo, ActivityInfo activityInfo) {
        super(player, mallInfo, activityInfo);
    }

    @Override
    protected boolean isRepeatedBuy(String orderNo) {
        return !player.getModule(DouLuoDaLuModule.class).canChargeSucceed(mallInfo.getMallId());
    }

    @Override
    protected void repeatedBuyLogic() {

    }

    @Override
    protected String addMall(String orderNo, RechargeOrder rechargeOrder) {
        String rewardStr = "";
        DouLuoDaLuModule douLuoDaLuModule = player.getModule(DouLuoDaLuModule.class);
        if(douLuoDaLuModule.canChargeSucceed(mallInfo.getMallId())){
            player.getModule(CurrencyModule.class).addCurrency(PropertyHelper.parseStringToProperty(mallInfo.getReward()),
                    eLogMoneyType.Recharge, eLogMoneyType.ReChargeGet);
            rewardStr = mallInfo.getReward();
            logger.info("订单: {}, 购买斗罗大陆礼包 商品: {}", orderNo, mallInfo.getMallId());
            douLuoDaLuModule.shopBuy(mallInfo.getMallId());

            //现金公告
            DouLuoDaLuConfig config = DouLuoDaLuMgr.getConfig();
            if(config != null){
                List<DouLuoDaLuEventInfo> list = config.getEventInfoList(eDouLuoDaLuEventType.ForestFair.getIntValue());
                if(list.size() > 0){
                    if(list.get(0).isShowLog()) {
                        douLuoDaLuModule.uploadRechargeEvent(mallInfo);
                    }
                }
            }
            // 加日志
            AutoLogMgr.add(new LogDouLuoDaLuBuyRmbMall(mallInfo.getActivityId(), player.getUserId(), douLuoDaLuModule.teamId, douLuoDaLuModule.regionId, mallInfo.getMallId(), mallInfo.getReward()));
        }
        return rewardStr;
    }
}
